<template>
  <div style="width: 100%">
  <a-card class="card" :bordered="false" >
    <div class="table-page-search-wrapper">
      <a-form layout="vertical">
        <a-row :gutter="48">
          <a-col :sm="{span:24}" :lg="{span:12}" :xl="{span:6}" >
            <a-form-item label="院系">
              <a-select :allowClear="true" v-model="queryParam.ssyxm" @change="yxChange">
                <a-select-option v-for="i in selectMenu.yx" :key="i.id" :value="i.dwh">{{ i.dwmc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:24}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="专业">
              <a-select :allowClear="true" v-model="queryParam.zy">
                <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <template v-if="advanced">
          <a-col :sm="{span:24}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="招生年度">
              <a-select :allowClear="true" v-model="queryParam.sznj">
                <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col ::sm="{span:24}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="学位层次">
              <a-select :allowClear="true" v-model="queryParam.sznj">
                <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          </template>
          <a-col :sm="{span:16}" :xl="{span:8}">
            <a-button type="primary" @click="loadData">查询</a-button>
            <a-button type="primary" @click="handleSave">保存</a-button>
            <a @click="advanced = !advanced" style="margin-left: 8px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>
          </a-col>
        </a-row>
      </a-form>
    </div>
  </a-card>
  <a-card class="card" :bordered="false">
    <a-table
      ref="table"
      size="default"
      rowKey="key"
      :columns="columns"
      :loading="loading"
      :dataSource="data"
      :alert="options.alert"
      :rowSelection="options.rowSelection"
      :pagination="false"
    >
      <span slot="serial" slot-scope="text, record, index">
        {{ index + 1 }}
      </span>
    </a-table>
    </a-card>
  </div>
</template>

<script>
// import moment from 'moment'
import { STable } from '~'
import { mapState } from 'vuex'

const selectArr = ['TYPE0126', 'TYPE0075', 'TYPE0125', 'TYPE0072']
export default {
  components: {
    STable
  },
  data () {
    return {
      advanced: true,
      loading: false,
      data: [],
      // 查询参数
      queryParam: {
        hzfs: 'yx'
      },
      postParams: {},
      // 表头
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: '研究方向代码',
          dataIndex: 'yjfxdm'
        },
        {
          title: '研究方向名称',
          dataIndex: 'yjfxmc'
        },
        {
          title: '所属院系',
          dataIndex: 'ssyx'
        },
        {
          title: '所属专业',
          dataIndex: 'sszy'
        },
        {
          title: '学位层次',
          dataIndex: 'xwcc'
        },
        {
          title: '研究方向序列',
          dataIndex: 'yjfxxl'
        }
      ],

      // custom table alert & rowSelection
      options: {
        alert: { show: false }
      },
      departmentsAddVisiable: false,
      departmentsEditVisiable: false,
      selectMenu: {
        yx: [] // 院系
      }
    }
  },
  computed: {
    ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0126: state => state.app['TYPE0126'] // 年级
    })
  },
  created () {
    this.initSelectMenu()
    this.loadData()
    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yx: res[0].data
        }
      })
    },
    // 选择院系
    yxChange (code) {
      this.$set(this.queryParam, 'sszym', '')
      this.$api.base.majorAll({lsdwh: code}).then(res => {
        this.$set(this.selectMenu, 'zy', res.data)
      })
    },
    // 加载数据
    loadData () {
      return new Promise(resolve => { resolve() }).then(res => {
        this.data = [{
          yjfxdm: 'window',
          yjfxmc: '微软',
          ssyx: '特别系',
          sszy: '程序',
          xwcc: '很高级',
          yjfxxl: '家里蹲',
          key: 1
        }, {
          yjfxdm: 'window',
          yjfxmc: '微软',
          ssyx: '特别系',
          sszy: '程序',
          xwcc: '很高级',
          yjfxxl: '家里蹲',
          key: 16
        }, {
          yjfxdm: 'window',
          yjfxmc: '微软',
          ssyx: '特别系',
          sszy: '程序',
          xwcc: '很高级',
          yjfxxl: '家里蹲',
          key: 15
        }]
      })
    },
    // 选择招生年度
    zsndChange () {

    },
    // 导出
    handleSave () {
      console.log('保存')
    }
  }
}
</script>

<style lang="less" scoped>
.card{
  margin-bottom: 20px;
}
</style>
